# Maintainer: Biswapriyo Nath <nathbappai@gmail.com>

_realname=unrar
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=7.1.6
pkgrel=1
pkgdesc='The RAR uncompression program (mingw-w64)'
arch=(any)
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clangarm64')
url='https://www.rarlab.com/rar_add.htm'
msys2_references=(
  "cpe: cpe:/a:rarlab:unrar"
)
license=('custom')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc")
source=("https://www.rarlab.com/rar/unrarsrc-${pkgver}.tar.gz"
        0001-fix-makefile.patch
        0002-fix-redefinition.patch
        0003-workaround-comsupp-library.patch)
sha256sums=('ca5e1da37dd6fa1b78bb5ed675486413f79e4a917709744aa04b6f93dfd914f0'
            '3746f9c07b6e41879787de69e9e31bbff2de36832e06a624818337b5c461f7cd'
            '9882f163dfbf04ad6946e99690799bb5de50894688fbe3f3df00e5c54f74e0b2'
            '707726b9280d7c929012e0c1d0af26b9fc86b8f3cb13ecd6c867e735adf722ba')

_apply_patch_with_msg() {
  for _patch in "$@"
  do
    msg2 "Applying ${_patch}"
    patch -p1 -i "${srcdir}/${_patch}"
  done
}

prepare() {
  cd ${_realname}

  _apply_patch_with_msg \
    0001-fix-makefile.patch \
    0002-fix-redefinition.patch \
    0003-workaround-comsupp-library.patch
}

build() {
  cd ${_realname}
  make
}

package() {
  cd ${_realname}
  install -Dm755 unrar.exe "${pkgdir}${MINGW_PREFIX}/bin/unrar.exe"
  install -Dm644 license.txt "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
